let { player, shopData, adPosition } = require('../shop/gameData');
let { show } = require('../game/alert');
const { ADS } = require('../ads/ADS');
const { videoAds } = require('../ads/video');
cc.Class({
    extends: cc.Component,

    properties: {
        label: {
            default: null,
            type: cc.Label
        },
        
    },
    // use this for initialization
    onLoad: function () {
        if(adPosition.map){
            this.node.active = false;
        }
    },
    
    // called every frame
    update: function (dt) {

    },

     back: function () {
        
       
    },

    loadAd : function () {
        
    },

    getAds : function () {
        show('未来提示','是否观看广告解锁', (res) => {
            if(res) {
                videoAds.showAd(cb => {
                    if(cb) {
                        this.node.active = false;
                        adPosition.map = true;
                    }
                })
            }
        })
    },
    openByMoney(){
        //钱够就开通
        //弹窗调用
        let cost = shopData.openMap.openMoney;
        if(player.money >= cost){
            player.money-=cost;
            this.node.active = false;
            adPosition.map = true;
            show('董事长提示',"开通成功",(e)=>{
                cc.log(e)
            })
        }else{
            show('董事长提示',"金钱不足,是否观看广告开通？",(res)=>{
                if(res){
                    //打开广告
                   videoAds.showAd((r)=>{
                        if(r){
                            this.node.active = false;
                            adPosition.map = true;
                        }
                   });
                }
            })
        }
        
       
    },
    checkReady : function () {
       

    },

   
});

    
